<?php

namespace app\api\model;
use think\Model;
use think\Config;

class Comment extends Model
{
    protected $table = 'jk_news_comments';

    //通过user_id 找出用户的头像
    public function getUserIconUrlAttr($value)
    {
    	// $res = \think\Db::table('jk_user_informations')->where('user_id', $value)->field('praise, commonly, negative_comment')->find();
    	$res = \think\Db::table('jk_users')->alias('u')
    		->where('u.user_id', $value)
    		->join('jk_user_informations m', 'm.user_id = u.user_id', 'LEFT')
    		->join('jk_user_third t', 't.openid = u.wechat_openid', 'LEFT')
    		->field('m.user_icon_url, t.avatar')
    		->find();
    	if(!empty($res['avatar'])){
    		$info = $res['avatar'];
    	} elseif(!empty($res['user_icon_url'])){
    		$info = Config::get('web.pic_url')['user'] . $res['user_icon_url'];
    	} else{
    		$info = Config::get('web.pic_url')['default'];
    	}

        return $info;
        // return $res;
    }

    //友好显示时间
    public function getCreateAtAttr($value)
    {
    	$res = friendlyDate($value);

    	return $res;
    }


}
